package vsqlbuilder.logic.sql;

import java.util.ArrayList;
import java.util.List;

public class QueryOrderedColumns {

	private List<QueryColumn> allIncludedColumns;

	public QueryOrderedColumns() {
		allIncludedColumns = new ArrayList<QueryColumn>();
	}

	public String getColumnNameAt(int index) {
		return this.allIncludedColumns.get(index).data.getName();
	}

	public String getColumnDatatypeAt(int index) {
		return this.allIncludedColumns.get(index).data.getDataType();
	}

	public int getNumberCols() {
		return this.allIncludedColumns.size();
	}

	public void addColumn(QueryColumn qcolumn) {
		this.allIncludedColumns.add(qcolumn);
	}

	public void removeColumn(String schemaName, String tableName,
			String columnName) {
		for (QueryColumn qc : this.allIncludedColumns) {
			if (qc.data.getParentTable().getSchemaName().equals(schemaName)) {
				if (qc.data.getParentTable().getName().equals(tableName)) {
					if (qc.data.getName().equals(columnName)) {
						this.allIncludedColumns.remove(qc);
						break;// [BUG FIX#5] 2/3 if continue iterating over
								// the modified list a exception is throw when
								// selecting or unselecting columns for a query.
					}
				}
			}
		}
	}

	public List<QueryColumn> getList() {
		return allIncludedColumns;
	}
}
